package com.jindy.module.returnapplyorder.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.module.returnapplyorder.domain.ReturnApplyProduct;
import com.jindy.module.returnapplyorder.service.IReturnApplyProductService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 回库申请单产品Controller
 *
 * @author ruoyi
 * @date 2022-10-19
 */
@RestController
@RequestMapping("/module/returnApplyProduct")
public class ReturnApplyProductController extends BaseController
{
    @Autowired
    private IReturnApplyProductService returnApplyProductService;

    /**
     * 查询回库申请单产品列表
     */
//    @PreAuthorize("@ss.hasPermi('module:returnApplyProduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReturnApplyProduct returnApplyProduct)
    {
        startPage();
        List<ReturnApplyProduct> list = returnApplyProductService.selectReturnApplyProductList(returnApplyProduct);
        return getDataTable(list);
    }

    /**
     * 导出回库申请单产品列表
     */
//    @PreAuthorize("@ss.hasPermi('module:returnApplyProduct:export')")
    @Log(title = "回库申请单产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReturnApplyProduct returnApplyProduct)
    {
        List<ReturnApplyProduct> list = returnApplyProductService.selectReturnApplyProductList(returnApplyProduct);
        ExcelUtil<ReturnApplyProduct> util = new ExcelUtil<ReturnApplyProduct>(ReturnApplyProduct.class);
        util.exportExcel(response, list, "回库申请单产品数据");
    }

    /**
     * 获取回库申请单产品详细信息
     */
//    @PreAuthorize("@ss.hasPermi('module:returnApplyProduct:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(returnApplyProductService.selectReturnApplyProductById(id));
    }

    /**
     * 新增回库申请单产品
     */
//    @PreAuthorize("@ss.hasPermi('module:returnApplyProduct:add')")
    @Log(title = "回库申请单产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReturnApplyProduct returnApplyProduct)
    {
        return toAjax(returnApplyProductService.insertReturnApplyProduct(returnApplyProduct));
    }

    /**
     * 修改回库申请单产品
     */
//    @PreAuthorize("@ss.hasPermi('module:returnApplyProduct:edit')")
    @Log(title = "回库申请单产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReturnApplyProduct returnApplyProduct)
    {
        return toAjax(returnApplyProductService.updateReturnApplyProduct(returnApplyProduct));
    }

    /**
     * 删除回库申请单产品
     */
//    @PreAuthorize("@ss.hasPermi('module:returnApplyProduct:remove')")
    @Log(title = "回库申请单产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(returnApplyProductService.deleteReturnApplyProductByIds(ids));
    }
}
